//
// Created by chizuru on 2025/9/2.
//

#include "RegisterReadCommand.h"

RegisterReadCommand::RegisterReadCommand(CameraDevice &comm, uint16_t addr, uint32_t *outPtr, RetryPolicy rp)
        : ICommand(), comm(comm), addr(addr), outPtr(outPtr), rp(rp) {}

bool RegisterReadCommand::execute() {
    auto v = comm.readRegister(addr);
    if (!v)
        return false;
    if (outPtr)
        *outPtr = *v;
    _lastValue = *v;
    return true;
}

// read is not modifying, undo is noop
bool RegisterReadCommand::undo() { return true; }

uint32_t RegisterReadCommand::lastValue() const { return _lastValue; }